package spring1;

import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import shuai.model.Computer;
import shuai.model.TestBean;
import shuai.model.User;

public class Demo {
	
	@Test
	public void test1(){
		BeanFactory beanFactory=new ClassPathXmlApplicationContext("applicationContext.xml");
		//System.out.println(beanFactory.containsBean("user"));
		User user=beanFactory.getBean("u",User.class);
		user.setName("kong");
		user.setAge(18);
		
		user.printInto();
		/*ClassPathXmlApplicationContext beanFactory=new ClassPathXmlApplicationContext("applicationContext.xml");
		beanFactory.destroy();此时才有destory方法*/
	}
	
	@Test
	public void test2(){
		BeanFactory beanFactory=new ClassPathXmlApplicationContext("applicationContext.xml");
		Computer computer=beanFactory.getBean("computer",Computer.class);
		computer.printComputerInfo();
	}
	
	@Test
	public void test3(){
		BeanFactory beanFactory=new ClassPathXmlApplicationContext("applicationContext.xml");
		TestBean testBean=beanFactory.getBean("testBean",TestBean.class);
		System.out.println(testBean.getProp());
	}
}
